<?php
/**
 * Created by PhpStorm.
 * User: lwt
 * Date: 5/15/19
 * Time: 4:24 PM
 */

namespace app\admin\model;

use think\Db;
use think\Model;

class BatchModel extends Model
{
	public static function addBatch($data){
		$msg = Db::table("tb_commodity")->where("co_id",$data["cos_id"])->find();
        $isNull = true;
        if (is_array($msg)){
            $isNull = false;
        }
        if ($isNull){
            return 0;
        }else{
        	$request = Db::table('tb_batch')->insert($data);
        	return $request;
        }
        
    }

    public static function deleteBatch($co_id){
        $msg = Db::table("tb_batch")->where("co_id",$co_id)->find();
        $isNull = true;
        if (is_array($msg)){
            $isNull = false;
        }
        if ($isNull){
            return 0;
        }else{
            $msg = Db::table('tb_batch')->delete($co_id);
            return $msg;
        }
    }

    public static function updateBatch($data){
        $msg = Db::table('tb_batch')->where('co_id', $data["co_id"])->update($data);
        return $msg;
    } 

    public static function selectBatchById($cos_id){
        $msg = Db::query('select *  from tb_batch where cos_id = ?',[$cos_id]);
        return $msg;
    }

    public static function selectBatchByCoId($co_id){
        $msg = Db::query('select *  from tb_batch where co_id = ?',[$co_id]);
        return $msg;
    }
}